package com.spring.webflux;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.time.Duration;

/**
 * <pre>
 * 功能描述：
 * </pre>
 *
 * @author: 李明杰
 * @date: 2024/3/7 16:57
 */
@RestController
public class WebFluxController {
    @GetMapping("/hello")
    public String hello() {
        return "Hello, WebFlux !";
    }

    @GetMapping("/user")
    public Flux<Integer> getUser() {
        return Flux.range(1, 7)
                .doOnComplete(() -> System.out.println("Completed"))
                .doOnNext(integer -> System.out.println("doOnNext=>" + integer))
                .delayElements(Duration.ofSeconds(1)).log();
    }
}
